package com.example.easyutils.musicpage;

import android.content.Context;
import android.database.DataSetObserver;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.easyutils.R;

import java.util.List;

public class MusicAdapter extends ArrayAdapter {
    private int resouceId;
    private Context context;
    private ImageView imageView;
    private TextView sinner,songName;

    public MusicAdapter(@NonNull Context context, int resource, @NonNull List objects) {
        super(context, resource, objects);
        this.resouceId = resource;
        this.context = context;
    }
//    public MusicAdapter(@NonNull Context context,  @NonNull List objects) {
//        super(context, R.layout.music_item, objects);
//        this.resouceId = R.layout.music_item;
//        this.context = context;
//    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        MusicUtil musicUtil = (MusicUtil) getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resouceId,parent,false);
        Log.d("获取测试",musicUtil.getNumber()+"");
        switch (musicUtil.getNumber()){
            case 1:
                imageView = (ImageView)view.findViewById(R.id.songImage);
                sinner = (TextView)view.findViewById(R.id.sinner);
                songName = (TextView)view.findViewById(R.id.songName);
                sinner.setText(musicUtil.getSinner());
                songName.setText(musicUtil.getSong());

                Glide
                        .with(context)
                        .load(musicUtil.getImageUrl())
                        .into(imageView);
                break;
            case 2:
                imageView = (ImageView)view.findViewById(R.id.musiclist_image);
                songName = (TextView) view.findViewById(R.id.musiclist_text);
                songName.setText(musicUtil.getMusicListName());
                Glide
                        .with(context)
                        .load(musicUtil.getCoverImgUrl())
                        .into(imageView);
                break;
        }

        return view;

    }
}
